import 'package:enterprise_v8/app/core/core.dart';

/// @description  自定义的搜索框组件
///[hintText] 提示字段
///[text] 提示字段
///[height] 高度
///[onCallBack]输入回调
class CustomSearchEnter extends StatelessWidget {
  CustomSearchEnter({
    super.key,
    this.hintText,
    this.text,
    this.height,
    this.onCallBack,
    this.onSubmitted,
    this.showIcon = true,
    this.textInputAction,
  }) {
    controller = TextEditingController(text: text);
    controller.selection = TextSelection.fromPosition(
      TextPosition(offset: controller.text.length),
    );
  }

  final String? hintText;
  final String? text;
  final double? height;
  final Function(String)? onCallBack;
  final Function(String)? onSubmitted;
  final bool showIcon;
  final TextInputAction? textInputAction;
  late final TextEditingController controller;

  @override
  Widget build(BuildContext context) {
    return Container(
        height: height ?? 32.w,
        padding: showIcon ? EdgeInsets.symmetric(horizontal: 12.w) : EdgeInsets.symmetric(horizontal: 3.w),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: Colors.white, border: Border.all(color: const Color(0xffF0F0F0), width: 1.w), borderRadius: BorderRadius.all(Radius.circular(8.w))),
        child: Row(
          children: [
            if (showIcon)
              // SvgPicture.asset(
              //   AppImages.icon_search,
              //   width: 16.w,
              // ),
            Expanded(
              child: TextField(
                keyboardType: TextInputType.text,
                textInputAction: textInputAction ?? TextInputAction.search,
                controller: text != null ? controller : null,
                onSubmitted: (value) {
                  onSubmitted?.call(value);
                },
                onChanged: (value) {
                  if (onCallBack != null) {
                    onCallBack!(value);
                  }
                },
                style: TextStyle(color: const Color(0xff222222), fontWeight: FontWeight.w400, fontSize: 14.sp),
                decoration: InputDecoration(
                  counterText: '',
                  //防止适配不居中
                  isCollapsed: true,
                  border: const OutlineInputBorder(borderSide: BorderSide.none),
                  contentPadding: EdgeInsets.only(left: 8.w),
                  hintText: hintText ?? '请输入',
                  hintStyle: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
                ),
              ),
            )
          ],
        ));
  }
}
